<script lang="ts" setup>
import type { StoreType } from "../composables/useStoreTypeManagement"

interface Props {
  storeType: StoreType
}

const props = defineProps<Props>()

const emit = defineEmits<{
  edit: [storeType: StoreType]
  delete: [storeType: StoreType]
}>()

// 处理编辑
function handleEdit() {
  emit("edit", props.storeType)
}

// 处理删除
function handleDelete() {
  emit("delete", props.storeType)
}

// 格式化日期
function formatDate(dateString: string) {
  return new Date(dateString).toLocaleDateString("zh-CN")
}
</script>

<template>
  <div class="store-type-card">
    <!-- 卡片头部 -->
    <div class="card-header">
      <div class="store-type-info">
        <div class="store-icon">
          <el-icon><ShoppingBag /></el-icon>
        </div>
        <div class="store-name">{{ storeType.name }}</div>
      </div>

      <!-- 操作按钮 -->
      <div class="action-buttons">
        <el-button
          link
          size="small"
          @click="handleEdit"
          class="edit-btn"
        >
          <el-icon><Edit /></el-icon>
        </el-button>
        <el-button
          link
          size="small"
          @click="handleDelete"
          class="delete-btn"
        >
          <el-icon><Delete /></el-icon>
        </el-button>
      </div>
    </div>

    <!-- 卡片内容 -->
    <div class="card-content">
      <div class="info-item">
        <span class="label">类型ID：</span>
        <span class="value">{{ storeType.id }}</span>
      </div>
      <div class="info-item">
        <span class="label">创建时间：</span>
        <span class="value">{{ formatDate(storeType.createdAt) }}</span>
      </div>
      <div class="info-item">
        <span class="label">关联人设：</span>
        <span class="value">{{ storeType.linkedPersonas }}个</span>
      </div>

      <!-- 状态提示 -->
      <div class="status-tip" v-if="storeType.linkedPersonas > 0">
        <el-icon><InfoFilled /></el-icon>
        <span>有关联人设，无法删除</span>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.store-type-card {
  background: var(--el-bg-color);
  border: 1px solid var(--el-border-color-lighter);
  border-radius: 8px;
  padding: 20px;
  transition: all 0.2s ease;

  &:hover {
    box-shadow: var(--el-box-shadow-lighter);
    border-color: var(--el-border-color);
  }

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;

    .store-type-info {
      display: flex;
      align-items: center;
      gap: 12px;

      .store-icon {
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--el-text-color-regular);
        font-size: 18px;
      }

      .store-name {
        font-size: 15px;
        font-weight: 600;
        color: var(--el-text-color-primary);
      }
    }

    .action-buttons {
      display: flex;
      gap: 4px;

      .el-button {
        padding: 4px;
        color: var(--el-text-color-regular);

        &.edit-btn:hover {
          color: var(--el-color-primary);
          background-color: var(--el-color-primary-light-9);
        }

        &.delete-btn {
          color: var(--el-color-danger);

          &:hover {
            color: var(--el-color-danger-dark-2);
            background-color: var(--el-color-danger-light-9);
          }
        }

        .el-icon {
          font-size: 16px;
        }
      }
    }
  }

  .card-content {
    .info-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;
      font-size: 13px;

      &:last-child {
        margin-bottom: 0;
      }

      .label {
        color: var(--el-text-color-secondary);
        font-weight: 500;
      }

      .value {
        color: var(--el-text-color-regular);
        font-weight: 400;
      }
    }

    .status-tip {
      display: flex;
      align-items: center;
      gap: 6px;
      margin-top: 12px;
      padding: 8px 12px;
      background: var(--el-color-warning-light-9);
      border: 1px solid var(--el-color-warning);
      border-radius: 6px;
      font-size: 11px;
      color: var(--el-color-warning-dark-2);

      .el-icon {
        font-size: 14px;
      }
    }
  }
}
</style>
